﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProxyWrapper.CommonProxyService;
namespace ProxyWrapper
{
    public class DatabaseServiceWrapper
    {
        CommonServiceSoapClient _client = null;
        public string[] AddDatabase(string dbName, bool isDataCaseSenitive, int loggedInUserId, byte[] data, List<int> associatedServices)
        {
            _client = new CommonServiceSoapClient();
            return _client.AddDatabase(dbName, isDataCaseSenitive, loggedInUserId, data, associatedServices != null ? associatedServices.ToArray() : null);
        }
        public string DeleteDatabase(int dbId, int loggedInUserId)
        {
            _client = new CommonServiceSoapClient();
            return _client.DeleteDatabase(dbId, loggedInUserId);
        }
        public string UpdateDatabase(int dbId, string newDBName, int loggedInUserId)
        {
            _client = new CommonServiceSoapClient();
            return _client.RenameDatabase(dbId, newDBName, loggedInUserId);
        }
        public List<ProxyWrapper.CommonProxyService.DatabaseDetails> GetDBList(int clientId)
        {
            _client = new CommonServiceSoapClient();
            return _client.GetClientDBList(clientId).ToList<ProxyWrapper.CommonProxyService.DatabaseDetails>();
        }
        public ProxyWrapper.CommonProxyService.DatabaseDetails GetDBDetail(int dbId, int clientId)
        {
            _client = new CommonServiceSoapClient();
            return _client.GetDbDetail(dbId, clientId);
        }
        public string ImportDatabase(byte[] data, int dbId, int loggedInUserId)
        {
            _client = new CommonServiceSoapClient();
            string _msg = _client.ImportData(data, dbId, loggedInUserId);
            return _msg;

        }
        public string EmptyDB(int clientId, int dbId, string hashCode)
        {
            _client = new CommonServiceSoapClient();
            return _client.EmptyDatabase(clientId, dbId, hashCode);
        }
        public string ExportDatabase(int dbId, int loggedInUserId)
        {
            _client = new CommonServiceSoapClient();
            byte[] _data = _client.ExportData(dbId, loggedInUserId);
            if (_data != null)
            {
                return Encoding.GetEncoding("iso-8859-1").GetString(_data);
            }
            else
            {
                return "0";
            }
        }
    }
}
